package cn.iocoder.yudao.module.handguard.service.userbasetable6;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable6.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable6.UserBaseTable6DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable6.UserBaseTable6Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable6.UserBaseTable6Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 企业贴息贷款 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable6ServiceImpl implements UserBaseTable6Service {

    @Resource
    private UserBaseTable6Mapper userBaseTable6Mapper;

    @Override
    public Long createUserBaseTable6(UserBaseTable6CreateReqVO createReqVO) {
        // 插入
        UserBaseTable6DO userBaseTable6 = UserBaseTable6Convert.INSTANCE.convert(createReqVO);
        userBaseTable6Mapper.insert(userBaseTable6);
        // 返回
        return userBaseTable6.getId();
    }

    @Override
    public void updateUserBaseTable6(UserBaseTable6UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable6Exists(updateReqVO.getId());
        // 更新
        UserBaseTable6DO updateObj = UserBaseTable6Convert.INSTANCE.convert(updateReqVO);
        userBaseTable6Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable6(Long id) {
        // 校验存在
        validateUserBaseTable6Exists(id);
        // 删除
        userBaseTable6Mapper.deleteById(id);
    }

    private void validateUserBaseTable6Exists(Long id) {
        if (userBaseTable6Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE6_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable6DO getUserBaseTable6(Long id) {
        LambdaQueryWrapper<UserBaseTable6DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable6DO::getApplicationId,id);
        return userBaseTable6Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable6DO> getUserBaseTable6List(Collection<Long> ids) {
        return userBaseTable6Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<UserBaseTable6DO> getUserBaseTable6Page(UserBaseTable6PageReqVO pageReqVO) {
        return userBaseTable6Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable6DO> getUserBaseTable6List(UserBaseTable6ExportReqVO exportReqVO) {
        return userBaseTable6Mapper.selectList(exportReqVO);
    }

}
